import 'package:flutter/material.dart';

import 'package:flutter_redux/flutter_redux.dart';
import 'package:my_flutter_github/common/dao/UserDao.dart';
import 'package:my_flutter_github/utils/NavigatorUtils.dart';
import 'package:redux/redux.dart';
import 'package:my_flutter_github/redux/MyState.dart';

import 'dart:async';

//启动欢迎界面
class WelcomePage extends StatefulWidget {
  // "/" 表示默认路由,这个一定要有
  static const sName = "/";
  @override
  _WelcomePageState createState() => _WelcomePageState();
}

class _WelcomePageState extends State<WelcomePage> {

  var hasInit = false;

  //该方法在initState初始化之后被调用，相当于onStart
  @override
  void didChangeDependencies() {
    super.didChangeDependencies();
    print("hasInit:$hasInit");
    if(hasInit) {
      //防止多次进入
      return;
    }

    Store<MyState> store = StoreProvider.of(context);

    new Future.delayed(new Duration(seconds: 2),(){
        UserDao.initUserInfo(store).then((result) {
            if(result != null && result.result) {
              print("go Home");
              NavigatorUtils.goHome(context);
            } else {
              print("go Login");
              NavigatorUtils.goLogin(context);
            }
            return true;
        });
    });

  }

  @override
  Widget build(BuildContext context) {
    return Container(
      color: Colors.white,
      child: new Center(
        child: new Image(image: new AssetImage('static/images/welcome.png')),
      ),
    );
  }
}
